<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的结构赋值</title>
  </head>

  <body>

  </body>
  <script>
    /* 
     对象的解构赋值
    */
    var obj = {
      name: "jason",
      age: 18,
      doWhat: function () {
        console.log("program");
      }
    }
    //1.在ES5里
    /* let name = obj.name;
    let age = obj.age;
    let doWhat = obj.doWhat; */

    //2.全部解构：等号左边的变量要和属性名相同
    /* let {
      name,
      age,
      doWhat
    } = obj;

    console.log(name);
    console.log(age);
    console.log(doWhat); */

    //3.部分解构

    /*  let {
       name
     } = obj;
     console.log(name); */

    //4.解构之后重新命名
    let {
      name: itsName
    } = obj
    console.log(itsName);

    //5.将现有的对象的方法赋值到某个变量
    let {
      random
    } = Math;
    let num = random();
    console.log(num);
  </script>

</html>